const WebSocket = require('ws')

// 在3000端口上建立 WebSocket 伺服器(随时都在线的服务)
const ws = new WebSocket.Server({ port: 3000 })

let count = 0

ws.on('connection', (obj) => {
    // console.log(obj);
    obj.on('message', (msg) => {
        // console.log(msg.toString());
        obj.send('收到了')
        setInterval(() => {
            count++
            obj.send(count)
        }, 2000)
    })
})